<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML>
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>注册</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="<%=basePath%>css/weui.css" />
<link rel="stylesheet" href="<%=basePath%>css/example.css" />
<script type="text/javascript" src="<%=basePath%>js/jquery.min.js"></script>
<script type="text/javascript" src="<%=basePath%>js/jquery.js"></script>
</head>
<script type="text/javascript">
var basePath="<%=basePath%>";
var yanzheng;
var invitationCode = '';

$(function(){
	invitationCode = getUrlParam("invitationCode");
	if(invitationCode!=''){
		$("#invitationCode").val(invitationCode)
	}

});

// 屏蔽屏幕自身手势
document.addEventListener('touchmove', function (e) { e.preventDefault(); }, false);
function toLogin(){
	window.location.href = "<%=basePath%>jsp/login.jsp";
}

function getUrlParam(name) {
	var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
	var r = window.location.search.substr(1).match(reg);
	if (r != null) return  decodeURI(r[2]); return null;
}


//注册
function toRegister(){

	var url="user/register.spring";
	var phone=$("#phone").val();
	var invitationCode1 = $("#invitationCode").val();
	var psw=$("#psw").val();
	var sex=$("#sex").val();
	var birthday=$("#birthday").val();
	var pswAgain=$("#pswAgain").val();
	var isRead = $("#s11").attr("checked")?1:0;
	
	if(phone==""){
		alert("请填写手机");
		return;
	}else if(invitationCode1==""){
		alert("请填写邀请码");
		return;
	}else if(psw==""){
		alert("请填写密码");
		return;
	}else if(pswAgain==""){
		alert("请输入确认密码");
		return;
	}else if(pswAgain!=""){
		if(pswAgain!=psw){
			alert("确认密码和密码不一致，请重复输入");
			$("#pswAgain").val("");
			return;
		}
	}else if(sex==""){
		alert("请选择性别");
		return;
	}else if(birthday==""){
		alert("请出生日期填写");
		return;
	}
	if(isRead==0){
		alert("请阅读并选择遵守免责声明");
		return;
	}
/*	var passNum = $("#passNum").val();
	if(passNum==""){
		alert("请输入验证码");
	}else{
		$.ajax({
		　　	url : "./user/checkSmsCode",
		　　	type : "POST",
			data : {
				sms:passNum
			},
			dataType : 'json',
		　　	success : function(data) {
				if(data.resultCode==0){*/
					var $loadingToast = $('#loadingToast');
					if ($loadingToast.css('display') != 'none') {
						return;
					}
					$loadingToast.show();
					$.ajax({
					　　	url : url,
					　　	data : {
							phone:phone,
							invitationCode:invitationCode1,
							password:psw,
							sex:sex,
							birthday:birthday,
							isRead : isRead
						},
					　　	type : "POST",
						dataType : 'json',
					　　	success : function(data) {
							if(data.resultCode==0){
								setTimeout(function() {
									$loadingToast.hide();
									$("#toast").show();
									setTimeout(function() {
										$("#toast").hide();
									}, 1000);
									window.location.href = basePath+"jsp/login.jsp?phone="+phone;
								}, 1000);
								
							}else if(data.resultCode==1){
								alert(data.msg);
								setTimeout(function() {
									$loadingToast.hide();
									window.location.href = basePath+"jsp/login.jsp?phone="+phone;
								}, 1000);
							}else{
								alert("注册失败，请重新注册");
								setTimeout(function() {
									$loadingToast.hide();
								}, 1000);
							}
					　　	},
					});
/*				}else{
					alert(data.msg);
				}
			}
		});
		
	}*/
}
//发送验证码
function sendPassNum(){
	var phoneNumReg = /(^[0-9]{3,4}\-[0-9]{7}$)|(^[0-9]{7}$)|(^[0-9]{3,4}[0-9]{7}$)|(^0{0,1}13[0-9]{9}$)/;
	var phone=$("#phone").val();
	var url=basePath+"SMS/sendMessage.spring";
	if(phone!=""){
		if(phoneNumReg.test(phone)){
			$("#send").text("已发送");
			$("#send").removeAttr('onclick');//去掉a标签中的onclick事件
			$.ajax({
			　　	url : url,
			　　	type : "POST",
				data : {
					phone:phone
				},
				dataType : 'json',
			　　	success : function(data) {

				}
			}); 
		}else {
			alert("请输入正确的手机号码");
		}
	}else {
		alert("请输入手机号码");
	}
}

// 检测是否为手机号码
function isTelOrMobile(telephone){  
    var teleReg = /^((0\d{2,3})-)(\d{7,8})$/;  
    var mobileReg =/^1[358]\d{9}$/;   
    if (!teleReg.test(telephone)){  
        return false;  
    }else{  
        return true;  
    }  
}  
// function checkIsExit(){
// var url=basePath+"user/checkUserIsExit.spring";
// 	$.ajax({
// 			　　	url : url,
// 			　　	type : "POST",
// 				data : {phone:phone},
// 				dataType : 'json',
// 			　　	success : function(data) {
// 					if(data.content=="1"){
// 					alert("该手机号已经被注册");
// 			　　		}else{
// 					$("#checkYes").show();
// 			}
// 				}
// 			}); 
// }
</script>
<body ontouchstart>
<div class="container js_container"></div>
	<div class="page">
		<div class="bd">
		<div class="hd">
        <h1 class="page_title">注册中心</h1>
    </div>
	<div class="weui_grids"></div>
	<div class="weui_cell">
		<div class="weui_cell_hd">
			<label class="weui_label" style="width: 6em">手机号码：</label>
		</div>
		<div class="weui_cell_bd weui_cell_primary">
			<input class="weui_input" type="number" name="phone" id="phone" placeholder="请输入手机号码" >
<!-- 		<i class="weui_icon_success" id="checkYes" style="display: none;"></i> -->
		</div>
	</div>
	<div class="weui_cell">
		<div class="weui_cell_hd">
			<label class="weui_label" style="width: 6em">邀请码&nbsp;&nbsp;：</label>
		</div>
		<div class="weui_cell_bd weui_cell_primary">
			<input class="weui_input" name="invitationCode" id="invitationCode" placeholder="请输入邀请码" >
			<!-- 		<i class="weui_icon_success" id="checkYes" style="display: none;"></i> -->
		</div>
	</div>
	<div class="weui_cell">
		<div class="weui_cell_hd">
			<label class="weui_label" style="width: 6em">密   &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;码：</label>
		</div>
		<div class="weui_cell_bd weui_cell_primary">
			<input class="weui_input" type="password" name="psw" id="psw" placeholder="请输入密码" onkeyup="value=value.replace(/[^\w\.\/]/ig,'')">
		</div>
	</div>
	<div class="weui_cell">
		<div class="weui_cell_hd">
			<label class="weui_label" style="width: 6em">确认密码：</label>
		</div>
		<div class="weui_cell_bd weui_cell_primary">
			<input class="weui_input" type="password" name="pswAgain" id="pswAgain" placeholder="请再次输入密码" onkeyup="value=value.replace(/[^\w\.\/]/ig,'')">
		</div>
	</div>
	<div class="weui_cell weui_cell_select weui_select_after">
                <div class="weui_cell_hd">
                 	  性 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;别：
            </div>
                <div class="weui_cell_bd weui_cell_primary">
                    <select class="weui_select" name="sex" id="sex" >
                   
                        <option value="0"  >男</option>
                        <option value="1" >女</option>
                    </select>
                </div>
            </div>
            <div class="weui_cell">
                <div class="weui_cell_hd">
                	<label for="birthday" class="weui_cell_hd">生 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;日：
                	</label>
               	</div>
                <div class="weui_cell_bd weui_cell_primary">
                    <input style="    font-weight: 700;font-size: 18px;margin-left: 7px" class="weui_input" type="date" placeholder="请输入出生日期" id="birthday" name="birthday" value="">
                </div>
            </div>
			<%--            <div class="weui_cell">
                    <div class="weui_cell_hd">
                        <label class="weui_label" style="width: 100%;">验&nbsp;&nbsp;证&nbsp;&nbsp;码：</label>
                    </div>
                    <div class="weui_cell_bd weui_cell_primary">
                        <input class="weui_input" type="text" style="width: 45%"  name="passNum" id="passNum" placeholder="请输入验证码">
                        <a class="weui_btn weui_btn_mini weui_btn_primary" style="vertical-align:middle;float: right;" onclick="sendPassNum();" id="send">发送验证码</a>
                    </div>
		
	</div>--%>
	</div>
	<div class="weui_cells weui_cells_checkbox" style="background-color: #FBF9FE">
            <label class="weui_cell weui_check_label" for="s11">
                <div class="weui_cell_hd">
                    <input type="checkbox" class="weui_check" name="checkbox1" id="s11" >
                    <i class="weui_icon_checked"></i>
                </div>
                <div class="weui_cell_bd weui_cell_primary" >
                    <p style="color: #000;font-size: 13px;">我已经阅读并遵守<a href="<%=basePath%>jsp/disclaimer.jsp">《<!-- 蒙估大夫 -->免责声明》</a></p>
                </div>
            </label>
        </div>
	<input class="weui_input" type="hidden" style="width: 45%"  name="msg" id="msg" >
		<div class="weui_btn_area">
			<a class="weui_btn weui_btn_primary login" href="javascript:"
				id="showTooltips" onclick="toRegister();">注册</a>
		</div>
		<div class="weui_extra_area" style="position: static;">
			<span style="color: #969696;">已有账号，请</span>
            <a onclick="toLogin();" style="color: #1c90f6;">前往登录</a>
        </div>
	</div>
	<div id="loadingToast" class="weui_loading_toast" style="display: none;">
				<div class="weui_mask_transparent"></div>
				<div class="weui_toast">
					<div class="weui_loading">
						<div class="weui_loading_leaf weui_loading_leaf_0"></div>
						<div class="weui_loading_leaf weui_loading_leaf_1"></div>
						<div class="weui_loading_leaf weui_loading_leaf_2"></div>
						<div class="weui_loading_leaf weui_loading_leaf_3"></div>
						<div class="weui_loading_leaf weui_loading_leaf_4"></div>
						<div class="weui_loading_leaf weui_loading_leaf_5"></div>
						<div class="weui_loading_leaf weui_loading_leaf_6"></div>
						<div class="weui_loading_leaf weui_loading_leaf_7"></div>
						<div class="weui_loading_leaf weui_loading_leaf_8"></div>
						<div class="weui_loading_leaf weui_loading_leaf_9"></div>
						<div class="weui_loading_leaf weui_loading_leaf_10"></div>
						<div class="weui_loading_leaf weui_loading_leaf_11"></div>
					</div>
					<p class="weui_toast_content">注册中...</p>
				</div>
			</div>
<!-- 			<input type="hidden" id="smsNum" name="smsNum" value=""/> -->
	<div id="toast" style="display: none;">
        <div class="weui_mask_transparent"></div>
        <div class="weui_toast">
            <i class="weui_icon_toast"></i>
            <p class="weui_toast_content" id="info">注册成功</p>
        </div>
    </div>
   
</body>
</html>
